import Vue from 'vue'
import Router from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'

Vue.use(Router)

//路由定向
const router =  new Router({
  routes: [
    {path: '/', redirect: '/login'},    //登录重定向
    {path: '/login', component: Login},
    {path: '/home', component: Home},
  ],
})

//挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   // to-目标路径  from-源路径  next-放行函数
//   if (to.path == '/login') return next();
//   const token = window.sessionStorage.getItem("LY_TOKEN"); 
//   console.log(token == null ? "token不存在" : token)
//   if (!token) return next('/login');   //不存在token则跳转login, 否则放行
//   next();
// })

export default router